var gl_material_vue_vm_list_html = $('#material_vue_vm_list').html();
var pageParam = null;

$(function() {
	$('#vue_vm_list div').hide();
	
	var pageParamStr = $.url().param('pageParam');
	pageParam = JSON.parse(pageParamStr);
	showParamInfo(pageParam);
	onDateChange();
});

function showParamInfo(pageParam) {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();
	$('#vue_vm_list').html(gl_vue_vm_list_html);
	
	new Vue({
		el: '#vue_vm_list',
		data: {
			todos: [pageParam]
		}
	});
	
	$('#vue_vm_list div').show();
}

function onDateChange() {
	pageParam.leaseStartTime = $('#startYear').val() + '-' + $('#startMonth').val() + '-' + $('#startDay').val();
	pageParam.leaseEndTime = $('#endYear').val() + '-' + $('#endMonth').val() + '-' + $('#endDay').val();
	pageParam.leaseDayNum = DateDiff(pageParam.leaseEndTime, pageParam.leaseStartTime);
	pageParam.totalRent = pageParam.rent * pageParam.leaseDayNum;
	pageParam.totalMoney = pageParam.totalRent + pageParam.pledge;
	$('#leaseDayNum').text(pageParam.leaseDayNum+'天');
	$('#totalRent').text(pageParam.totalRent+'元');
	$('#pledge').text(pageParam.pledge+'元');
	$('#totalMoney').text(pageParam.totalMoney+'元');
}

function saveGoNextPage() {
	var loginedUser = getLoginedUser();
	pageParam.staffId = loginedUser.staffId ;
	pageParam.staffName = loginedUser.staffName;
	pageParam.createTime = loginedUser.createTime;
	pageParam.leaseType = 1;
	pageParam.leaseStatus = 1;
	pageParam.totalFee = pageParam.totalMoney;
	pageParam.payWay = parseInt($('input:radio[name="payWay"]:checked').val());

	save_basic(path+'/lease/save', {lease:pageParam}, function() {
		var url = '5-1-1ynrent-3.html?pageParam=' + encodeURIComponent(JSON.stringify(pageParam));
		window.open(url);
	});
}

function saveGoNextPageOutSide() {
	var loginedUser = getLoginedUser();
	pageParam.staffId = loginedUser.staffId ;
	pageParam.staffName = loginedUser.staffName;
	pageParam.createTime = loginedUser.createTime;
	pageParam.leaseType = 2;
	pageParam.leaseStatus = 1;
	pageParam.totalFee = pageParam.totalMoney;
	pageParam.payWay = parseInt($('input:radio[name="payWay"]:checked').val());
	
	save_basic(path+'/lease/save', {lease:pageParam}, function() {
		var url = '5-1-2ywrent-3.html?pageParam=' + encodeURIComponent(JSON.stringify(pageParam));
		window.open(url);
	});
}

function deleteBatch() {
	deleteBatch_basic(path+'/lease/deleteBatch');
}

function findElder(onSuccess) {
	var searchVal = pageParam.elderName;
	
	find_basic(path+'/elder/find', searchVal, function(response) {
		if(response.data.length>0) {
			pageParam.elderId = response.data[0].elderId;
			
			if(onSuccess) {
				onSuccess();
			}
		}
	});
}